<template>
    <uni-popup ref="popup" type="dialog">
      <uni-popup-dialog 
        :type="type" 
        :cancelText="cancelText" 
        :confirmText="confirmText" 
        :title="title" 
        :content="content" 
        @confirm="handleConfirm" 
        @close="handleClose"
      ></uni-popup-dialog>
    </uni-popup>
  </template>
  
  <script>
  export default {
    name: 'ConfirmDialog'
  }
  </script>
  
  <script setup>
  import { ref } from 'vue';
  
  // Props
  const props = defineProps({
    type: {
      type: String,
      default: 'warn'
    },
    title: {
      type: String,
      default: '提示'
    },
    content: {
      type: String,
      default: ''
    },
    cancelText: {
      type: String,
      default: '取消'
    },
    confirmText: {
      type: String,
      default: '确定'
    },
    // 确认回调函数
    confirmCallback: {
      type: Function,
      default: null
    },
    // 取消回调函数
    cancelCallback: {
      type: Function,
      default: null
    }
  });
  
  // Emits
  const emit = defineEmits(['confirm', 'close']);
  
  // 弹窗引用
  const popup = ref(null);
  
  // 打开弹窗
  const open = () => {
    popup.value.open();
  }
  
  // 关闭弹窗
  const close = () => {
    popup.value.close();
  }
  
  // 确认按钮回调
  const handleConfirm = () => {
    emit('confirm');
    if (props.confirmCallback) {
      props.confirmCallback();
    }
  }
  
  // 关闭按钮回调
  const handleClose = () => {
    emit('close');
    if (props.cancelCallback) {
      props.cancelCallback();
    }
  }
  
  // 暴露方法给外部使用
  defineExpose({
    open,
    close
  });
  </script>
  
  <style lang="scss" scoped>
  /* 弹窗组件基于uni-popup，无需额外样式 */
  </style>